package com.example.zzm.yuejian03.Fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zzm.yuejian03.Activity.DingdanActivity;
import com.example.zzm.yuejian03.Activity.GuanzhuActivity;
import com.example.zzm.yuejian03.Activity.LoginActivity;
import com.example.zzm.yuejian03.Activity.MypictureActivity;
import com.example.zzm.yuejian03.Activity.ShezhiActivity;
import com.example.zzm.yuejian03.Bean.MyBean;
import com.example.zzm.yuejian03.Listener.TListener;
import com.example.zzm.yuejian03.Model.MyModel;
import com.example.zzm.yuejian03.R;
import com.squareup.picasso.Picasso;

import static android.content.Context.MODE_PRIVATE;


public class MyFragment extends BaseFragment{

    private Button button4,button3,button2,button1,button;
    private ImageView imageView4;
    private TextView textView10;
    private int userid;
    private SharedPreferences sp;

    @Override
    void initView() {
        button3=view.findViewById(R.id.button3);
        button4=view.findViewById(R.id.button4);
        button2=view.findViewById(R.id.button2);
        button = view.findViewById(R.id.button);
        button1 = view.findViewById(R.id.button1);
        textView10 = view.findViewById(R.id.textView10);
        imageView4 = view.findViewById(R.id.imageView4);

        sp = getActivity().getSharedPreferences("userInfo",MODE_PRIVATE);
        userid=sp.getInt("user_id",1);
        MyModel myModel = new MyModel();
        myModel.getMys(userid,listener);
    }

    @Override
    void initEvent() {

        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), LoginActivity.class));
                getActivity().onBackPressed();
            }
        });
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), ShezhiActivity.class));
            }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), DingdanActivity.class));
            }
        });
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), MypictureActivity.class));
            }
        });
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), GuanzhuActivity.class));
            }
        });
    }

    @Override
    void initData() {
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view= inflater.inflate(R.layout.fragment_my,container,false);
        initData();
        initView();
        initEvent();
        return  view;
    }

    TListener<MyBean> listener = new TListener<MyBean>() {
        @Override
        public void onResponse(MyBean club) {
            textView10.setText(club.getReal_name());
            Picasso.with(getContext())
                    .load("http://10.0.2.2/yuejian10/public/static/asstes/images/" + club.getUser_pic())
                    .placeholder(R.mipmap.ic_launcher)
                    // .memoryPolicy(MemoryPolicy.NO_CACHE)
                    .into(imageView4);
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(getContext(),"没有得到数据",Toast.LENGTH_SHORT).show();
        }
    };

    public interface OnFragmentInteractionListener {
    }
}
